package com.example.work4;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;

public class MyService extends Service {

    private int count = 0;
    private boolean quit = false;
    private MyServiceBinder myServiceBinder = new MyServiceBinder();
    private Handler mHandler = new Handler();
    private Runnable runnable = new Runnable() {
        @Override
        public void run() {
            count++;
            if(!quit){
                mHandler.postDelayed(runnable,1000);
            }
        }
    };

    public MyService() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        return myServiceBinder;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mHandler.post(runnable);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        quit = true;
    }

    public class MyServiceBinder extends Binder {
        public int getCount(){
            return MyService.this.count;
        }
        public int getResult(String numa, String numb){ System.out.println("123"); return Integer.parseInt(numa) + Integer.parseInt(numb); }
    }
}

